package com.ruoyi.web.controller.module.product;

import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.product.ProductAttrResult;
import com.ruoyi.system.service.module.product.IProductAttrResultService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商品属性详情Controller
 *
 * @author ruoyi
 * @date 2021-08-11
 */
@Validated
@Api(value = "商品属性详情控制器", tags = {"商品属性详情管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/product/attr/result")
public class ProductAttrResultController extends BaseController {

    private final IProductAttrResultService productAttrResultService;

    /**
     * 查询商品属性详情列表
     */
    @ApiOperation("查询商品属性详情列表")
    @GetMapping("/list")
    public TableDataInfo<ProductAttrResult> list(@Validated ProductAttrResult productAttrResult) {
        return PageUtils.buildDataInfo(productAttrResultService.page(PageUtils.buildPage()));
    }

    /**
     * 获取商品属性详情详细信息
     */
    @ApiOperation("获取商品属性详情详细信息")
    @GetMapping("/{id}")
    public AjaxResult<ProductAttrResult> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(productAttrResultService.getById(id));
    }

    /**
     * 新增商品属性详情
     */
    @ApiOperation("新增商品属性详情")
    @Log(title = "商品属性详情", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ProductAttrResult productAttrResult) {
        return toAjax(productAttrResultService.save(productAttrResult) ? 1 : 0);
    }

    /**
     * 修改商品属性详情
     */
    @ApiOperation("修改商品属性详情")
    @Log(title = "商品属性详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ProductAttrResult productAttrResult) {
        return toAjax(productAttrResultService.updateById(productAttrResult) ? 1 : 0);
    }

    /**
     * 删除商品属性详情
     */
    @ApiOperation("删除商品属性详情")
    @Log(title = "商品属性详情" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(productAttrResultService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
